/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Generics_01.java]
 * Creation Date        [08-12-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_other;

/**
 * 泛型相关面试题
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Generics_01 {

	/**
	 * 编写一个泛型方法, 实现指定位置元素的交换
	 */
	public <T> void swap(T[] array, int index1, int index2) {
		T temp = array[index1];
		array[index1] = array[index2];
		array[index2] = temp;
	}

	/**
	 * 编写一个泛型方法, 实现指定数组的逆序排序
	 */
	public <T> void reverse(T[] array) {
		int start = 0;
		int end = array.length - 1;

		while (true) {
			if (start >= end) {
				break;
			}
			T temp = array[start];
			array[start] = array[end];
			array[end] = temp;

			start++;
			end--;
		}
	}

}
